package com.xiangge.lianxi;

import java.util.Scanner;

public class Demo4 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("输入一个正整数:");
        int n = input.nextInt();

        if (n<1){
            System.err.println("输入错误");
            return;
        }

        int sum = 0;
        /*for (int i = 0; i <= n; i++) {
            if (i % 2 != 0) {
                sum += i;
            } else {
                sum -= i;
            }
        }*/
        int i = 0;
        while (i <= n) {
            if (i % 2 != 0) {
                sum += i;
            } else {
                sum -= i;
            }
            i++;
        }

        System.out.println("sum = " + sum);
    }
}
